<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "clazz".
 *
 * @property int $ID ID
 * @property int $ZYID 专业ID
 * @property string $NJ 年级
 * @property string $BJBH 班级编号
 * @property string $BZRXM 班主任姓名
 * @property string|null $BZRGH 班主任工号
 *
 * @property Major $zY
 * @property Student[] $students
 */
class Clazz extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'clazz';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['ZYID', 'NJ', 'BJBH', 'BZRXM'], 'required'],
            [['ZYID'], 'integer'],
            [['NJ', 'BJBH'], 'string', 'max' => 10],
            [['BZRXM'], 'string', 'max' => 50],
            [['BZRGH'], 'string', 'max' => 20],
            [['ZYID'], 'exist', 'skipOnError' => true, 'targetClass' => Major::className(), 'targetAttribute' => ['ZYID' => 'ID']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'ID' => 'ID',
            'ZYID' => '专业ID',
            'NJ' => '年级',
            'BJBH' => '班级编号',
            'BZRXM' => '班主任姓名',
            'BZRGH' => '班主任工号',
        ];
    }

    /**
     * Gets query for [[ZY]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getZY()
    {
        return $this->hasOne(Major::className(), ['ID' => 'ZYID'])->inverseOf('clazzs');
    }

    /**
     * Gets query for [[Students]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getStudents()
    {
        return $this->hasMany(Student::className(), ['BJID' => 'ID'])->inverseOf('bJ');
    }
}
